#include "Comprehension.h"
#include "IVisitor.h"

Comprehension::Comprehension(const exprTypePtr& target, const exprTypePtr& iter, const ExprTypeList& ifs, int nodeId):
    comprehensionType(nodeId),
    _target(target),
    _iter(iter),
    _ifs(ifs)
{
}
    
Comprehension::~Comprehension()
{
    _ifs.clear();
}
    
Ast::AstTypes Comprehension::type() const
{
    return Ast::Comprehension;
}
    

exprTypePtr Comprehension::target()
{
    return _target;
}

void Comprehension::setTarget(const exprTypePtr& target)
{
    _target = target;
}

exprTypePtr Comprehension::iter()
{
    return _iter;
}

void Comprehension::setIter(const exprTypePtr& iter)
{
    _iter = iter;
}

ExprTypeList Comprehension::ifs()
{
    return _ifs;
}

void Comprehension::setIfs(const ExprTypeList& ifs)
{
    _ifs = ifs;
}

    
QString Comprehension::toString() const
{
    return QString("Comprehension[target=%1, iter=%2, ifs=%3]").
                arg(_target ? _target->toString():"").
                arg(_iter ? _iter->toString():"").
                arg(_ifs.toString());
}
    
void Comprehension::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitComprehension(node.dynamicCast<Comprehension>());
}
    
void Comprehension::traverse(IVisitor* visitor)
{
    if (_target != NULL)
        _target->accept(visitor, _target);
    if (_iter != NULL)
        _iter->accept(visitor, _iter);
    _ifs.traverse(visitor);
}